<template>
    <div>
        <h1>{{msg}}</h1>
        <button @click="getStudents">获取学生信息</button><br>
        {{students}}<br>
        <button @click="getCars">获取车辆信息</button><br>
        {{cars}}
    </div>    
</template>

<script>
export default {
    name: 'HelloWorld',
    data() {
        return {
            msg: '你好啊',
            students: [],
            cars: []
        }
    },
    methods:{
        getStudents() {
            this.$http.get('http://localhost:8080/student-api/students').then(
                response => {
                    this.students = response.data
                },
                error => { console.log(error.message) }
            )
        },
        getCars() {
            // this.$http.get('http://localhost:8080/car-api/cars').then(
            //     response => {
            //         this.cars = response.data
            //     },
            //     error => {
            //         console.log(error.message)
            //     }
            // )

            this.$http.get('http://localhost:8080/car-api/cars')
            .then(
                response => {
                    this.cars = response.data
                }
            )
            .catch(
                error => {
                    console.log(error.message)
                }
            )
        }
    }
}
</script>

<style scoped>

</style>
